home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 6 / FM Towns Free Software Collection 6.iso / t_os / helper / source / helper.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-08  |  8.0 KB  |  371 lines

  1. #include    <stdio.h>
  2. #include    <stdlib.h>
  3. #include    <string.h>
  4. #include    <ctype.h>
  5. #include    <mos.h>
  6. #include    <fmcfrb.h>
  7. #include    <kkstr2.h>
  8. #include    "scrn.h"
  9. #include    "keyword.h"
  10. #include    "graphic.h"
  11. #include    "dir.h"
  12. #include    "file.h"
  13. #include    "coldef.h"
  14.  
  15. char    *strdup();
  16.  
  17. extern char    *crent_drive;
  18. extern char    work[];
  19.  
  20.        char    index_file[128];
  21.        int    cur_x=0;
  22.        int    cur_y=0;
  23. static int    kb_act=0;
  24. static int     kb_flg=0;
  25. static int     ch_bak=0;
  26. static unsigned ec_bak=0;
  27. static int    kan_col[]={ 15,14,2,13,4,5,6,8,7,9,10,11,12,3,1,0 };
  28.  
  29. void    GetDspPos(int *x, int *y)
  30. {
  31.     *x = cur_x;
  32.     *y = cur_y;
  33. }
  34. void    Tango_Touroku(char *str)
  35. {
  36.     memcpy(str,0,80);
  37. }
  38. void    KAN_init()
  39. {
  40.     KANJ    kana;
  41.  
  42.     kana.scrn   = KAN_SCRN16;   /*  画面モードは16色モード               */
  43.     kana.egbw   = work;         /*  EGBのワークアドレスを設定する            */
  44.     kana.wPage  = 0;            /*  表示ページを0にする                */
  45.     kana.mosAp  = KAN_MOSON;    /*  マウスの制御をする                 */
  46.     kana.gets   = Tango_Touroku;/*  文字取得ルーチンの設定                 */
  47.     kana.getPos = GetDspPos;    /*  未確定文字列表示位置取得関数の設定 */
  48.     kana.maxX   = 639;          /*  画面の最大X座標                    */
  49.     kana.maxY   = 479;          /*  画面の最大Y座標                    */
  50.  
  51.     KAN_prepare(&kana);
  52.     KAN_setClrTbl(kan_col);
  53. }
  54. int    PRG_clic(int no)
  55. {
  56.     int     i,n;
  57.     int     fg;
  58.     char    tmp[256];
  59.  
  60.     if ( prg_tbl[no] == NULL )
  61.     return (no + PRG_NO);
  62.  
  63.     if ( prg_tbl[no]->dir != NULL ) {
  64.     DSP_mos(2);
  65.     if ( prg_tbl[no]->manual == NULL ) {
  66.         if ( (prg_tbl[no]->manual = 
  67.             file_serch(prg_tbl[no]->dir,"*.RRR")) == NULL ) {
  68.             if ( (prg_tbl[no]->manual = 
  69.                 file_serch(prg_tbl[no]->dir,"*.MAN")) == NULL )
  70.             prg_tbl[no]->manual = 
  71.                     file_serch(prg_tbl[no]->dir,"*.DOC");
  72.         }
  73.     }
  74.     if ( prg_tbl[no]->readme == NULL ) {
  75.         if ( (prg_tbl[no]->readme = 
  76.             file_serch(prg_tbl[no]->dir,"*.GGG")) == NULL )
  77.         prg_tbl[no]->readme = 
  78.                 file_serch(prg_tbl[no]->dir,"*.DOC");
  79.     }
  80.     if ( prg_tbl[no]->copycnt == 0 ) {
  81.         if ( (prg_tbl[no]->copy[0] = 
  82.             file_serch(prg_tbl[no]->dir,"*.QQQ")) == NULL ) {
  83.         strcpy(tmp,prg_tbl[no]->dir);
  84.         joint_path(tmp,"*.*");
  85.         prg_tbl[no]->copy[0] = strdup(tmp);
  86.         }
  87.         prg_tbl[no]->copycnt++;
  88.     }
  89.     DSP_mos(0);
  90.     }
  91.  
  92.     MSG_disp("%-41.41s",prg_tbl[no]->name);
  93.     MENU_mask(RETN_NO,ON);
  94.     MENU_mask(LIST_NO,OFF);
  95.     MENU_mask(PRNT_NO,OFF);
  96.     MENU_mask(INST_NO,prg_tbl[no]->copycnt > 0 ? ON:OFF);
  97.     MENU_mask(EXIT_NO,OFF);
  98.  
  99.     if ( prg_tbl[no]->readme != NULL ) {
  100.     MENU_mask(LIST_NO,prg_tbl[no]->manual != NULL ? ON:OFF);
  101.     FILE_open(prg_tbl[no]->readme);
  102.     fg = 0;
  103.     } else if ( prg_tbl[no]->manual != NULL ) {
  104.     MENU_mask(TEXT_NO,prg_tbl[no]->readme != NULL ? ON:OFF);
  105.     FILE_open(prg_tbl[no]->manual);
  106.     fg = 1;
  107.     } else {
  108.     FILE_open(NULL);
  109.     fg = (-1);
  110.     }
  111.  
  112.     n = NON_NO;
  113.     for ( ; ; ) {
  114.     while ( (i = MENU_no(0)) == n )
  115.         FILE_irq();
  116.     n = i;
  117.  
  118.     if ( i == CLER_NO )
  119.         break;
  120.     else if ( i == LIST_NO ) {
  121.         if ( fg == 0 && prg_tbl[no]->manual != NULL ) {
  122.         MENU_mask(TEXT_NO,prg_tbl[no]->readme != NULL ? ON:OFF);
  123.         FILE_open(prg_tbl[no]->manual);
  124.         fg = 1;
  125.         } else if ( fg == 1 && prg_tbl[no]->readme != NULL ) {
  126.         MENU_mask(LIST_NO,prg_tbl[no]->manual != NULL ? ON:OFF);
  127.         FILE_open(prg_tbl[no]->readme);
  128.         fg = 0;
  129.         }
  130.     } else if ( i == PRNT_NO )
  131.         FILE_lpt();
  132.     else if ( i == INST_NO )
  133.         COPY_all(prg_tbl[no]->copycnt,prg_tbl[no]->copy);
  134.     else if ( i == BACK_NO )
  135.         FILE_back();
  136.     else if ( i == NEXT_NO )
  137.         FILE_next();
  138.  
  139.     }
  140.  
  141. #ifdef    DEBUG
  142.     MENU_mask(CLER_NO,OFF);
  143.     MENU_mask(LIST_NO,ON);
  144.     MENU_mask(PRNT_NO,ON);
  145.     MENU_mask(INST_NO,ON);
  146.     MENU_mask(EXIT_NO,ON);
  147. #else
  148.     MENU_mask(CLER_NO,OFF);
  149.     MENU_mask(LIST_NO,ON);
  150.     MENU_mask(PRNT_NO,OFF);
  151.     MENU_mask(INST_NO,OFF);
  152.     MENU_mask(EXIT_NO,ON);
  153. #endif
  154.     MSG_disp("%-41.41s","");
  155.     FILE_close();
  156.     PRG_status();
  157.  
  158.     return i;
  159. }
  160. int    LIST_proc(void)
  161. {
  162.     int     i,n;
  163.     int     fg=0;
  164.     char    *p,*s;
  165.  
  166. LOOP:
  167.     if ( (p = FILE_select()) == NULL )
  168.     return LIST_NO;
  169.  
  170.     if ( JOKE_run(p) )
  171.     goto LOOP;
  172.  
  173.     MENU_mask(RETN_NO,ON);
  174.     MENU_mask(LIST_NO,OFF);
  175.     MENU_mask(PRNT_NO,ON);
  176.     MENU_mask(INST_NO,OFF);
  177.     MENU_mask(EXIT_NO,OFF);
  178.     FILE_open(p);
  179.  
  180.     n = NON_NO;
  181.     for ( ; ; ) {
  182.     while ( (i = MENU_no(0)) == n )
  183.         FILE_irq();
  184.     n = i;
  185.  
  186.     if ( i == CLER_NO )
  187.         break;
  188.     else if ( i == PRNT_NO )
  189.         FILE_lpt();
  190.     else if ( i == BACK_NO )
  191.         FILE_back();
  192.     else if ( i == NEXT_NO )
  193.         FILE_next();
  194.  
  195.     }
  196.  
  197. #ifdef    DEBUG
  198.     MENU_mask(CLER_NO,OFF);
  199.     MENU_mask(LIST_NO,ON);
  200.     MENU_mask(PRNT_NO,ON);
  201.     MENU_mask(INST_NO,ON);
  202.     MENU_mask(EXIT_NO,ON);
  203. #else
  204.     MENU_mask(CLER_NO,OFF);
  205.     MENU_mask(LIST_NO,ON);
  206.     MENU_mask(PRNT_NO,OFF);
  207.     MENU_mask(INST_NO,OFF);
  208.     MENU_mask(EXIT_NO,ON);
  209. #endif
  210.     FILE_close();
  211.     PRG_status();
  212.  
  213.     goto LOOP;
  214. }
  215. void    main(int argc,char *argv[])
  216. {
  217.     int     i,n,cdrv;
  218.     char    *p;
  219.     char    *exp;
  220.     char    tmp[4];
  221.  
  222.     cdrv = getdrv();
  223.     tmp[0] = cdrv + 'A'; tmp[1] = ':'; tmp[2] = '\0';
  224.     crent_drive = tmp;
  225.     exp = argv[0];
  226.     index_file[0] = '\0';
  227.  
  228.     if ( argc > 1 ) {
  229.     while ( --argc > 0 ) {
  230.         p = *(++argv);
  231.         if ( *p == '-' || *p == '/' ) {
  232.         switch(toupper(*(p+1))) {
  233.         case 'D':
  234.             p += (*(p+2) == '=' ? 3:2);
  235.             crent_drive = p;
  236.             break;
  237.         }
  238.         } else
  239.         strcpy(index_file,p);
  240.     }
  241.  
  242.     }
  243.  
  244.     if ( index_file[0] == '\0' ) {
  245.     p = exp;
  246.     if ( p[0] != '\0' && p[1] != ':' ) {
  247.         index_file[0] = 'A' + cdrv;
  248.         index_file[1] = ':';
  249.     } else {
  250.         index_file[0] = *(p++);
  251.         index_file[1] = *(p++);
  252.     }
  253.     index_file[2] = '\0';
  254.  
  255.     if ( crent_drive == tmp )
  256.         crent_drive = strdup(index_file);
  257.  
  258.     if ( *p != '\\' ) {
  259.         getdir(index_file+2);
  260.         if ( index_file[3] != '\0' )
  261.         strcat(index_file,"\\");
  262.     }
  263.     strcat(index_file,p);
  264.     if ( (p = strrchr(index_file,'\\')) == NULL )
  265.         for ( p = index_file ; *p != '\0' ; p++ );
  266.     strcpy(p,"\\HELPER.IDX");
  267.     }
  268.  
  269.     DSP_init();
  270.     KAN_init();
  271.  
  272.     DSP_mos(2);
  273.  
  274.     ICON_init();
  275.     SCRN_init();
  276.     DB_init(index_file);
  277.     KEY_cler();
  278.  
  279. #ifdef    DEBUG
  280.     MENU_mask(CLER_NO,OFF);
  281.     MENU_mask(LIST_NO,ON);
  282.     MENU_mask(PRNT_NO,ON);
  283.     MENU_mask(INST_NO,ON);
  284.     MENU_mask(EXIT_NO,ON);
  285. #else
  286.     MENU_mask(CLER_NO,OFF);
  287.     MENU_mask(LIST_NO,ON);
  288.     MENU_mask(PRNT_NO,OFF);
  289.     MENU_mask(INST_NO,OFF);
  290.     MENU_mask(EXIT_NO,ON);
  291. #endif
  292.  
  293.     DSP_mos(0);
  294.  
  295.     n = NON_NO;
  296.     for ( ; ; ) {
  297.     while ( (i = MENU_no(1)) == n );
  298.     n = i;
  299.  
  300.     if ( i == EXIT_NO ) {
  301.         if ( yesno("Are You Sure ?") != (-1) )
  302.             break;
  303.     } else if ( i == CLER_NO )
  304.         KEY_cler();
  305.     else if ( i == LIST_NO )
  306.         i = LIST_proc();
  307. #ifdef    DEBUG
  308.     else if ( i == PRNT_NO )
  309.         PLT_control();
  310.     else if ( i == INST_NO )
  311.         KEY_input();
  312. #endif
  313.     else if ( i == BACK_NO )
  314.         PRG_back();
  315.     else if ( i == NEXT_NO )
  316.         PRG_next();
  317.     else if ( i >= PRG_NO )
  318.         i = PRG_clic(i - PRG_NO);
  319.     else if ( i >= KEY_NO )
  320.         KEY_clic(i - KEY_NO);
  321.  
  322.     }
  323.  
  324.     KAN_disp(KAN_DISPOFF);
  325.     KAN_finish();
  326.     DSP_end();
  327.     chdrv(cdrv);
  328. }
  329. void    INKEY_start(void)
  330. {
  331.     kb_act = 1;
  332.     KYB_clrbuf();
  333.     KAN_disp(KAN_DISPON);
  334. }
  335. void    INKEY_end(void)
  336. {
  337.     kb_act = 0;
  338.     KAN_disp(KAN_DISPOFF);
  339. }
  340. int    kbhit(void)
  341. {
  342.     if ( kb_flg != 0 )
  343.     return 1;
  344.  
  345.     do {
  346.     ch_bak = KYB_read(1,&ec_bak);
  347.     } while ( KAN_inpchk() == KAN_MISET );
  348.  
  349.     if ( (ec_bak & 0xFF00) == 0xFF00 )
  350.     return 0;
  351.  
  352.     kb_flg = 1;
  353.     return 1;
  354. }
  355. int    getch(void)
  356. {
  357.     if ( kbhit() == 0 )
  358.     return EOF;
  359.  
  360.     kb_flg = 0;
  361.     if ( ch_bak  != 0xFFFF ) {
  362.     if ( (ch_bak & 0x8000) != 0 || (ec_bak & 0xFF00) > 0x5100 )
  363.         ch_bak = 0xFFFF;
  364.     switch(ec_bak&0xFF00) {
  365.     case 0x7300: ch_bak = 0x000D; break;
  366.     case 0x7200: ch_bak = 0x001B; break;
  367.     }
  368.     }
  369.     return ((ch_bak & 0xFF00) == 0xFF00 ? EOF:ch_bak);
  370. }
  371.